﻿(function () {
    'use strict';

    angular
        .module('app.Diagnosis')
        .factory('DiagnosisProvider', DiagnosisProvider);

    DiagnosisProvider.$inject = ['$http'];

    /* @ngInject */
    function DiagnosisProvider($http) {
        var service = {

            SetAllDiagnosisList: SetAllDiagnosisList,
            GetDiagnosisListForPage: GetDiagnosisListForPage,
            GetPatientDiagnosis: GetPatientDiagnosis,
            GetFilteredDiagnosisList: GetFilteredDiagnosisList,
            SavePatientDiagnosis: SavePatientDiagnosis
        };

        return service;
        /////////////////////
        var DiagnosisList;
        var apiLocation = "https://api.remezion.com/api/";

        function SetAllDiagnosisList(DefaultList) {
            DiagnosisList = DefaultList;
            return DiagnosisList.length;
        }

        function GetPatientDiagnosis(ReferralID) {
            if (!ReferralID)
            {
                ReferralID = 0;
            }
            return $http.get(apiLocation + 'PatientDiagnosis/' + ReferralID);
        }

        function GetFilteredDiagnosisList(ReferralID, SearchText) {
            var data = "{'ReferralID':'" + ReferralID + "','SearchText':'" + SearchText + "'}";
            return $http.post(apiLocation + 'FilterDiagnosis', data);
        }

        function GetDiagnosisListForPage(pagenumber,pagelimit)
        {
            var PageList = DiagnosisList.slice(pagenumber * pagelimit, (pagenumber * pagelimit) + pagelimit);
            return PageList;
        }

        function SavePatientDiagnosis(ReferralID, DiagnosisCodes,DiagnosisNotes) {
            var data = "{'ReferralID':'" + ReferralID + "','DiagnosisIDs':'" + DiagnosisCodes + "','DiagnosisNotes':'" + DiagnosisNotes + "'}";
            return $http.post(apiLocation + 'PatientDiagnosis', data);
        }
    }
}());
